This document has opened in a new window. Close the window to continue with ArgoSphere.


What is JavaScript?

Just as a dogfish is not a dog, JavaScript is not Java!

It is an easy-to-learn and simple-to-use scripting language which is embedded directly into an HTML page. It requires no compiling and can be mastered by anyone who is not daunted by HTML.

It probably provides the simplest way of enhancing web pages and making them much more interactive.

 

Some examples of how JavaScript can be used.

Changing more than one frame with one click

With HTML, a hyperlink can change the contents of only one frame (although that frame may contain its own set of frames).
With JavaScript you can change any number of frames with one click.

frame1 frame2 frame3
frame4 frame5 frame6
function change3frames() {
parent.frame2.location.href="doc1.htm"
parent.frame4.location.href="doc2.htm"
parent.frame6.location.href="doc3.htm"
}

This JavaScript function will load new pages (doc1.htm, doc2.htm, doc3.htm) into frames 2, 4 and 6.

 

Click buttons

Buttons can be used to make things happen.

<form>
<input type="button" value="Click me" onClick="alert('Here is a clue.')">
</form>

This code, for example, will display a button:   

If the button is clicked on, a small window pops up:   

Buttons can also be used to open windows, change frame contents, or perform many other JavaScript functions.

 

User input

One of the most useful JavaScript facilities for authors of educational web pages is testing input. You can ask a question and then check whether the child's response is correct. The following script checks whether the answer is "4" and loads a "yes" or "no" page accordingly.

function test(answer) {
var response = form.input.value;
if (response == "4")
location.href="yes.htm"
else
location.href="no.htm";
}
<form method="GET" name="answer">
<input type="text" name="input">
</form>

It is also possible to perform operations on input so, for example, you could write a function which would multiply two input numbers and display the result.

 

Open new window

There are many occasions when it is useful to open a new window. You can do this with HTML but, as the new window frequently obscures the old window, the user is unaware that there is more than one window open. JavaScript allows you to open a window of specified dimensions (usually small so that it is obvious that a new window has opened). You can also specify whether the window will have a toolbar, status bar, or scrollbars; and whether or not the window can be resized.

function openwindow() {
newwindow = open("test.htm","testwindow","width=300,height=200,status=no,toolbar=no,menubar=no");
}

A window can be closed with:

function closewindow() {
close();
}

 

On-the-fly documents

One of the most exciting JavaScript features is the ability to create on-the-fly-documents. If, for example, a child typed in some words, a document could be created which would contain those words.

 

Changing images

With JavaScript 1.1 you can easily change an image on a page, either by clicking on a link or simply moving the mouse over the image. Try doing that with HTML!

 

Want to know more?

There are several good tutorials available on the Web. But you will, of course, need a JavaScript-capable browser.


To quit this page, close the window.